package eiisan.forkjointest.recursivetask;

import java.util.concurrent.RecursiveTask;

public class Fibonacci extends RecursiveTask<Integer> {
   final int n;
    public Fibonacci(int n) { this.n = n; }
    public Integer compute() {
     if (n <= 1){
         // System.out.println(Thread.currentThread().getName() + " compute ===> " + n);
         return n;
     }

     Fibonacci f1 = new Fibonacci(n - 1);
     f1.fork();
     Fibonacci f2 = new Fibonacci(n - 2);
     return f2.compute() + f1.join();
   }
 }
